import React, { Component } from 'react'
import {HotWrap} from '../Home'
import {get} from '../../utils/http'
import { withRouter} from "react-router-dom"
  class Hot extends Component {
    constructor(){
        super()
        this.state={
            data:[]
        }
    }
   async componentDidMount(){
        let result=await get('https://m.tuniu.com/travel/mapi/channel/getCmsChannelAjax?pageId=2698&cityCode=200')
        this.setState({
            data:result.data.data[2].gItems[1].mItems
        })          
    }
    handleclick=async (value)=>{
        let str=value.phCatAppUrl       
        let re=/\d+$/g;
       let id=str.match(re)[0]
        console.log(id); 
        let result=await get(`https://m.tuniu.com/travel/mapi/search/getSearchList?bookCity=200&bookCityName=北京&limit=20&paramType=2&keyword=&tabKey=whole&catId=${id}&locateCityCode=200&searchKeys=[]&pageNum=1&newSaleChannels=[]&_=1575975774534088161610433619390`)
     //  console.log(result.data.data);      
     let flag=1 
        this.props.history.push({pathname: `/hotcity/${value.phCatName}/${id}/${flag}`, state: { data:result.data.data}})   
    }

    render() {
        return (
            <HotWrap>
                <p><i></i> <span> 热门地点</span></p>
                <ul>
                    {
                        this.state.data.map((value,index)=>{
                       return (<li key={value+index} onClick={() => {
                             this.handleclick(value)
                       }
                       }  > 
                         {value.phCatName} 
                       </li> )  
                        })                      
                    }    
                    <li>搜索更多</li>
                </ul>
            </HotWrap>
        )
    }
}

export default withRouter(Hot)